﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net;
using System.IO;
using System.Windows.Threading;


namespace SharePointExplorer.UserControls
{
    /// <summary>
    /// Interaction logic for ImageViewer.xaml
    /// </summary>
    public partial class ImageViewer : UserControl
    {
        App app = (App)Application.Current;
        public ImageViewer()
        {
            
        }

        public ImageViewer(string FileName)
        {

            InitializeComponent();
            SharePointExplorer.Classes.KinectHelper.TogglePostureDetectedHandler(false);
            app.MainWindowInstance.DeactivateButton.Visibility = Visibility.Visible;
            app.MainWindowInstance.HomeButton.Visibility = Visibility.Visible;
            app.MainWindowInstance.backButton.Visibility = Visibility.Visible;
            imgShow.Source = null;

            BitmapImage bmp = new BitmapImage(new Uri(FileName));
            imgShow.Source = bmp;
            //var url = new Uri(FileName);

            //var webRequest = WebRequest.CreateDefault(url);
            //webRequest.Credentials = CredentialCache.DefaultCredentials;

            //webRequest.ContentType = "image/jpeg";

            //webRequest.BeginGetResponse((ar) =>
            //{
                
            //    var response = webRequest.EndGetResponse(ar);
                                                        

            //    var stream = response.GetResponseStream();

            //    if (stream.CanRead)
            //    {

            //        Byte[] buffer = new Byte[response.ContentLength];

            //        stream.BeginRead(buffer, 0, buffer.Length, (aResult) =>
            //        {

            //            stream.EndRead(aResult);

            //            string pt = System.IO.Path.GetTempPath() + "test.jpg";
            //            File.WriteAllBytes(pt, buffer);

            //            BitmapImage image = new BitmapImage();

            //            image.BeginInit();

            //            image.StreamSource = new MemoryStream(buffer);

            //            image.EndInit();

            //            image.Freeze();

            //            this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(delegate
            //            {

            //                imgShow.Source = image;

            //            }));

            //        }, null);

            //    }

            //}, null);

            //this.Show();
        }

       
    }
}
